package com.example.administrator.yuejian2.activity;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.CompoundButton;
import android.widget.RadioButton;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.fragment.MyAttentionClubFragment;
import com.example.administrator.yuejian2.fragment.MyAttentionMasterFragment;

public class MyAttentionActivity extends BaseActivity {

    private MyAttentionClubFragment myAttentionClubFragment;
    private MyAttentionMasterFragment myAttentionMasterFragment;
    private FragmentTransaction fragmentTransaction;
    private FragmentManager fragmentManager;
    private RadioButton myAttentionClub, myAttentionMaster;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_attention);

        initView();
        initEvents();
    }

    private void initView() {
        myAttentionClub = findViewById(R.id.myAttentionClub);
        myAttentionMaster = findViewById(R.id.myAttentionMaster);
    }

    private void initEvents() {
        myAttentionClub.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    if (myAttentionClubFragment == null) {
                        myAttentionClubFragment = new MyAttentionClubFragment();
                    }
                    fragmentTransaction = fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.my_attention_layout, myAttentionClubFragment);
                    fragmentTransaction.commit();
                }
            }
        });

        myAttentionMaster.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    if (myAttentionMasterFragment == null) {
                        myAttentionMasterFragment = new MyAttentionMasterFragment();
                    }
                    fragmentTransaction = fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.my_attention_layout, myAttentionMasterFragment);
                    fragmentTransaction.commit();
                }
            }
        });

        fragmentManager = getSupportFragmentManager();
        myAttentionClub.setChecked(true);

    }


}
